package com.example.zhyq.visit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.base.mvvm.BaseActivity
import com.example.zhyq.R
import com.example.zhyq.databinding.ActivityVisitApproveBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/VisitApproveActivity")
class VisitApproveActivity : BaseActivity<ActivityVisitApproveBinding,VisitViewModel>() {

    @Autowired
    @JvmField
    var vid = ""

    override fun initView() {
        ARouter.getInstance().inject(this)
        vm.getVisitById(vid.toInt())

        binding.headVisitdetail.apply {
            headerBack.setOnClickListener {
                finish()
            }
            headerTitle.text = "访客详情"
        }

        binding.visitdetailBtn.setOnClickListener {
            val buttonId = binding.visitdetailRg.checkedRadioButtonId
            if (buttonId==R.id.visitdetail_yes) {
                //通过
                vm.approveVisit(vid.toInt())
            }else {
                //驳回
                vm.rejectVisit(vid.toInt())
            }
        }
    }

    override fun initData() {
        vm.getVisitById.observe(this) {
            binding.bean = it
            if (it.visitStatus=="待审核"){
                binding.visitdetailGroup.visibility = View.VISIBLE
            }
        }

        vm.approveVisit.observe(this) {
            ToastUtils.showLong("审核通过")
            finish()
        }

        vm.rejectVisit.observe(this) {
            ToastUtils.showLong("驳回了")
            finish()
        }
    }
}